package com.base.cn.platform.os.entity.exam.extend;

import com.base.cn.platform.os.common.mybatis.BaseEntity;
import com.base.cn.platform.os.common.mybatis.SqlExclude;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.google.gson.Gson;
import lombok.Data;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;

/**
 * 用户考试扩展数据对象
 *
 * @author s.li
 * @date 2018/12/07
 */
@Data
public class ExamUserExpand extends BaseEntity {
    /**学员ID*/
    private BigDecimal userId;
    /**自由组卷规则JSON*/
    private String custom;
    /**总做题量*/
    private Integer totalCount;
    /**总错题量*/
    private Integer errorCount;
    /**考试次数*/
    private Integer examCount;
    /**历史考试总分*/
    private Integer totalScore;
    /**最后选择的专业ID串*/
    private String lastSelectSubjectIds;
    /** 总题量 */
    @SqlExclude
    private Long totalSumCount;
    /**
     * 统计总做题量
     */
    @SqlExclude
    private Double totalSumPrecision;

    //===========================================
    /**成绩排名*/
    private int rank;
    /**与前一名相关的百分比*/
    private float rankPrev;
    /**平均正确率*/
    private float averagePrecision;
    /**平均错误率*/
    private float errorPrecision;
    /**平均成绩*/
    private float averageScore;
    /**自由组卷规则对象*/
    private  CustomJson customMap;

    public CustomJson getCustomMap(){
        String _custom = this.getCustom();
        if(StringUtils.isNotEmpty(_custom)){
            try {
                _custom = URLDecoder.decode(_custom,"utf-8");
            } catch (UnsupportedEncodingException e) {
                return null;
            }
            Gson gson = new Gson();
            return gson.fromJson(_custom,CustomJson.class);
        }
        return null;
    }
}
